package net.sangpil.classes.visual
{
	import flash.geom.Point;
	
	public class Arrangement
	{	
		
		//public static var ORDER_ASCENDING:String = 'orderAscending';
		//public static var ORDER_DESCENDING:String = 'orderDescending';
		
		/**
		 * 
		 * @param objArr 객체들의 배열값.
		 * @param property 어떤 속성을 변경할 것인지. 예를들어 x 좌표에 대해서.
		 * @param relatedProperty 어떤 속성이 관계되어 더해지는지. 예를들어 width값.
		 * @param space 추가되는 간격.
		 * @param startPoint 시작포인트. 없으면 배열 첫번째의 해당 속성값으로 초기화됨.
		 * 
		 */		
		public static function Order_Descending(objArr:Array, property:String, relatedProperty:String, space:Number = 0, startPoint:Number = 0):void
		{
			if(objArr[0].hasOwnProperty(property))
			{
				var defaultPosition:Number = (startPoint == 0) ? objArr[0][property] : startPoint;
				var addingNumber:Number = 0;
				
				for(var i:uint = 0; i < objArr.length; i++)
				{
					var rp:Number = objArr[i][relatedProperty];
					objArr[i][property] = addingNumber + defaultPosition;
					addingNumber += rp+space;
				}
			}else{
				trace('there is no property ', property);
			}
		}
		
		public static function Order_Ascending(objArr:Array, property:String, relatedProperty:String, space:Number = 0, startPoint:Number = 0):void
		{
			if(objArr[0].hasOwnProperty(property))
			{
				var defaultPosition:Number = (startPoint == 0) ? objArr[0][property] : startPoint;
				trace(defaultPosition);
				var	subtractingNumber:Number = 0;
				
				for(var i:uint = 0; i < objArr.length; i++)
				{
					var rp:Number = objArr[i][relatedProperty];
					subtractingNumber += rp;
					objArr[i][property] = defaultPosition - subtractingNumber;
					subtractingNumber += space;
				}
			}else{
				trace('there is no property ', property);
			}
		}
		
		public static function Get_Descending_Positions(objArr:Array, property:String, relatedProperty:String, space:Number = 0, startPoint:Number = 0):Array
		{
			var arr:Array = new Array;
			
			if(objArr[0].hasOwnProperty(property))
			{
				var defaultPosition:Number = (startPoint == 0) ? objArr[0][property] : startPoint;
				var addingNumber:Number = 0;
				
				for(var i:uint = 0; i < objArr.length; i++)
				{
					var rp:Number = objArr[i][relatedProperty];
					arr[i] = addingNumber + defaultPosition;
					addingNumber += rp+space;
				}
			}else{
				trace('there is no property ', property);
			}
			
			return arr;	
		}
		
		public static function Get_Ascending_Positions(objArr:Array, property:String, relatedProperty:String, space:Number = 0, startPoint:Number = 0):Array
		{
			var arr:Array = new Array;
			
			if(objArr[0].hasOwnProperty(property))
			{
				var defaultPosition:Number = (startPoint == 0) ? objArr[0][property] : startPoint;
				trace(defaultPosition);
				var	subtractingNumber:Number = 0;
				
				for(var i:uint = 0; i < objArr.length; i++)
				{
					var rp:Number = objArr[i][relatedProperty];
					subtractingNumber += rp;
					arr[i] = defaultPosition - subtractingNumber;
					subtractingNumber += space;
				}
			}else{
				trace('there is no property ', property);
			}
			
			return arr;	
		}
		
		public function Arrangement()
		{
		}
	}
}